import axios from 'axios';
   // https://dog.ceo/api/breed/pembroke/images/random
    import { ref,reactive, onMounted } from 'vue';

    export default function (){
    let dogs= reactive([
        {name:'小狗1',src:'https://images.dog.ceo/breeds/pembroke/n02113023_5022.jpg'},
    ])

    async function changeDog(){
/*         axios.get('https://dog.ceo/api/breed/pembroke/images/random').then(res=>{
            console.log(res.data.message);
            dogs.push({name:'小狗2',src:res.data.message})
        }) */
        try{
            let result = await axios.get('https://dog.ceo/api/breed/pembroke/images/random')
            console.log(result.data.message);
            dogs.push({name:'小狗2',src:result.data.message})
        }catch(err){
            console.log(err);
            alert('请求失败')
        }
        
    }
    onMounted(()=>{
        changeDog()})
    //内部数据和方法
    //向外部提供数据或者方法
    return {dogs,changeDog}
}